package org.mch.func.m_px.sorteg.utils;

import javax.swing.AbstractButton;
import javax.swing.JPanel;

/**
 * 描述：移动按钮组件工具类；<BR/>
 * 
 * @author MCH；<BR/>
 *
 */
public class MoveComponentGoBtnSort {

	public static int MOVEBTNTIME = 1;

	public void moveButton(AbstractButton btn, int toX, int toY, JPanel panel) throws Exception {
		int curX = btn.getX();
		int curY = btn.getY();

		if (curY == toY) {
			if (curX > toX) {
				for (int i = curX; i >= toX; i--) {
					Thread.sleep(MOVEBTNTIME);
					btn.setLocation(i, toY);
				}
			} else {
				for (int i = curX; i <= toX; i++) {
					Thread.sleep(MOVEBTNTIME);
					btn.setLocation(i, toY);
				}
			}
			panel.updateUI();
		} else if (curX == toX) {
			if (curY > toY) {
				for (int i = curY; i >= toY; i--) {
					Thread.sleep(MOVEBTNTIME);
					btn.setLocation(toX, i);
				}
			} else {
				for (int i = curY; i <= toY; i++) {
					Thread.sleep(MOVEBTNTIME);
					btn.setLocation(toX, i);
				}
			}
			panel.updateUI();
		}
	}
}
